<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
Route::get('/tt',function (){
    return time();
})->middleware('auth:api');

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/test', 'MemberController@index')->name('test');

//接管路由··
$api = app('Dingo\Api\Routing\Router');

//定义一个版本分组。这种定义方式有利于后续为相同端点新增多版本支持。同时指定了指定了控制器的命名空间
$api->version('v1',['namespace' => 'App\Api\Controllers\V1'], function ($api) {

    //$api->get('members/{id}', 'App\Api\Controllers\V1\UserController@info');
    $api->get('demo/{id?}', 'MemberController@demo');

    //会员
    $api->get('members/{id?}', ['as' => 'members.find', 'uses' => 'MemberController@find']);
    $api->put('members/{id?}', ['as' => 'members.update', 'uses' => 'MemberController@update']);
    $api->post('members', ['as' => 'members.save', 'uses' => 'MemberController@save']);
    $api->delete('members/{id?}', ['as' => 'members.delete', 'uses' => 'MemberController@delete']);

    //壁纸
    $api->get('wallpapers/{id?}', ['as' => 'wallpapers.find', 'uses' => 'WallpaperController@find']);
    $api->put('wallpapers/{id?}', ['as' => 'wallpapers.update', 'uses' => 'WallpaperController@update']);
    $api->post('wallpapers', ['as' => 'wallpapers.save', 'uses' => 'WallpaperController@save']);
    $api->delete('wallpapers/{id?}', ['as' => 'wallpapers.delete', 'uses' => 'WallpaperController@delete']);

    //壁纸类目
    $api->get('wallpapers_category/{id?}', ['as' => 'wallpapers_category.find', 'uses' => 'WallpaperCategoryController@find']);
    $api->put('wallpapers_category/{id?}', ['as' => 'wallpapers_category.update', 'uses' => 'WallpaperCategoryController@update']);
    $api->post('wallpapers_category', ['as' => 'wallpapers_category.save', 'uses' => 'WallpaperCategoryController@save']);
    $api->delete('wallpapers_category/{id?}', ['as' => 'wallpapers_category.delete', 'uses' => 'WallpaperCategoryController@delete']);

    //通过路由别名，生成url
    $api->get('route_url_demo',function (){
        //你需要提供一个版本，这样才能基于这个版本的路由生成正确的 URL。并且允许你在不同版本中使用相同的名字。
        return app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('members.find',1);
    });

    //$api->get('members/{id}', 'UserController@info');//获取单个用户信息

    //$api->get('members/', 'UserController@ls');//获取用户列表

});